import DList from "@/components/dlist";
// import searchBox from "./components/search_box.vue";
import bottomBar from "../home/components/bottom_bar.vue";
import evaluationPopup from "../home/components/evaluation_popup";
export default {
  data() {
    return {
      active_name: "1",
      order_type: "",
      evaluation_show: false,
      orderList: [],
      orderTabList: [{
        name: "全部订单",
        value: ""
      },{
        name: "待支付订单",
        value: "wait_pay"
      },{
        name: "待审核订单",
        value: "wait_check"
      },{
        name: "待接单订单",
        value: "wait_accept"
      },{
        name: "待服务订单",
        value: "wait_work"
      },{
        name: "已完成订单",
        value: "completed"
      },{
        name: "超时退单",
        value: "overtime"
      },{
        name: "已关闭订单",
        value: "close"
      }],
      loading: false,
      finished: false,
      page: 1,
      order_id: ""
    };
  },
  activated() {
    this.init();
    this.getOrderData('');
  },
  methods: {
    init() {
      this.orderList = [];
      this.loading = false;
      this.finished =false;
      this.page = 1;
    },
    optionType(type) {
      this.order_type = type;
      this.init();
      this.getOrderData(type);
    },
    // 跳转订单详情
    goOrderDetail(type,order_id) {
      this.$router.push(
        this.fun.getUrl("anyOrderDetail", {type,order_id})
      );
    },
    async getOrderData(tab) {
      if (this.loading === true || this.finished === true) {
        return;
      }
      this.loading = true;
      let url = this.active_name == '1' ? 'plugin.be-within-call.frontend.order.personal-need.index' : 'plugin.be-within-call.frontend.order.enterprise-need.index'
      let { data, result, msg } = await $http.get(url, { tab , page: this.page});
      if (result === 0) {
        this.$toast(msg);
        return;
      }
      if (data.data.length === 0 || data.data.length < data.per_page || data.current_page === data.last_page) {
        this.finished = true;
      }
      this.total = data.total;
      this.orderList.push(...data.data);
      this.page++;
      this.loading = false;
    },
    onLoad() {
      this.getOrderData();
    },
    async evenButtonModels(citem,item) {
      console.log(citem,item,'citem,itemcitem,item');
      this.order_id = item.order_id;
      if(citem.value == 'pay') {
        this.$router.push(
          this.fun.getUrl("orderpay", {
            status: 2,
            order_ids: item.order_id
          })
        );
      }else if(citem.value == 'cancel-pay' || citem.value == 'enterprise-cancel-pay') {
        let { data, result, msg } = await $http.post(citem.api, { oid: item.order_id });
        this.$toast(msg);
        this.init();
        this.getOrderData('');
      }else if(citem.value == 'receive') {
        this.$dialog.confirm({
          title: '提示',
          message: '是否确认完成?',
        })
          .then(async () => {
            let { data, result, msg } = await $http.post(citem.api, { oid: item.order_id });
            this.$toast(msg);
            this.init();
            this.getOrderData('');
          })
          .catch(() => {
            // on cancel
          });
      }else if(citem.value == 'publish') {
        this.evaluation_show = true;
      }
    },
    clickTab() { 
      console.log(this.active_name,11223);
      if(this.active_name == '1') {
        this.orderTabList = [{
          name: "全部订单",
          value: ""
        },{
          name: "待支付订单",
          value: "wait_pay"
        },{
          name: "待审核订单",
          value: "wait_check"
        },{
          name: "待接单订单",
          value: "wait_accept"
        },{
          name: "待服务订单",
          value: "wait_work"
        },{
          name: "已完成订单",
          value: "completed"
        },{
          name: "超时退单",
          value: "overtime"
        },{
          name: "已关闭订单",
          value: "close"
        }]
      }else if(this.active_name == '2') {
        this.orderTabList = [{
            name: "全部订单",
            value: ""
          },{
            name: "待支付订单",
            value: "wait_pay"
          },{
            name: "待审核订单",
            value: "wait_check"
          },{
            name: "已完成订单",
            value: "completed"
          },{
            name: "已关闭订单",
            value: "close"
          }]
      }
      this.init();
      this.getOrderData('');
    },
    commentEvent() {
      this.init();
      this.getOrderData('');
    }
  },
  components: { DList , bottomBar , evaluationPopup}
};
